﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Text;
using System.Collections;
using Eis51.CampanyCMS.Business.Bus;
using Eis51.CampanyCMS.Model.Bus;
using Eis51.CampanyCMS.Model;

namespace Eis51.Web.dataPage
{
    /// <summary>
    /// $codebehindclassname$ 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class PurchaseMenu : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            StringBuilder sb = new StringBuilder();

            LoadNews(ref sb);

            context.Response.Write("[ " + sb.ToString() + "]");
        }

        public class ShowModel
        {

            public int Seqno { get; set; }

            public string Title { get; set; }

        }


        private void LoadNews(ref StringBuilder hoemData)
        {
            string scondition = string.Format(" Licd={0} and Isfirst>0 ", AppContext.LCID);
            scondition += " order by LasteUpdateby desc ";
            IList list = ProductsBLL.GetInstance().Search(scondition);
            ShowModel showModel = null;
            Products model = null;
            string tmpStr = string.Empty;


            string where = string.Format(" Licd={0} and Isfirst>0 order by [Level] desc ", AppContext.LCID);
            IList listPurchase = PurchaseBLL.GetInstance().Search(where);

            if (null == list || list.Count == 0 || null == listPurchase || listPurchase.Count == 0)
            {
                return;
            }
            Purchase modelPurchase = null;
            if (null != listPurchase && listPurchase.Count > 0)
            {
                foreach (var etPurchase in listPurchase)
                {
                    modelPurchase = (Purchase)etPurchase;
                    foreach (var et in list)
                    {
                        model = (Products)et;
                        if (modelPurchase.ProductID == model.Seqno)
                        {
                            showModel = new ShowModel { Seqno = model.Seqno, Title = model.Title };
                            tmpStr = Eis51.Web.common.common.JavaScriptSerializerString(showModel);
                            hoemData.Append(",");
                            hoemData.Append(tmpStr);
                            break;
                        }
                    }
                }
            }
            

        }


        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}
